{include file="header/index" /}
<style>

</style>
<div class="newContentBox">
	<div class="fixedFather">
		<div class="fix">
			新增客户
			<span class="newNotice"><span class="newtext">*</span>为必填项</span>
			<div class="newFixBtnBox">
				<button type="button" class="newBtnDefault newBtnGray" onclick="returnBack(this)"> <i class="fa fa-mail-reply"></i>返回</button>
			</div>
		</div>
	</div>
	
	<form action="" class="layui-form newListPart ">
		<div class="newPart">
			<div class="newTitle">
				<i class="fa fa-address-book allColor icon"></i>	客户信息
			</div>

			<div class="newContent">
				<div class="layui-form-item cover_layui_f_i">
					<label class="layui-form-label cover_layui_f_l"><span class="cover_new_label">*</span> 客户姓名</label>
					<div class="layui-input-block cover_layui_i_b">
						<input type="text" name="realname" required  lay-verify="required" placeholder="请输入客户姓名" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item cover_layui_f_i">
					<label class="layui-form-label cover_layui_f_l"><span class="cover_new_label">*</span> 客户电话</label>
					<div class="layui-input-block cover_layui_i_b">
						<input type="text" name="telphone" required  lay-verify="required" placeholder="请输入客户电话" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item cover_layui_f_i">
					<label class="layui-form-label cover_layui_f_l"><span class="cover_new_label">*</span> 性别</label>
					<div class="layui-input-block cover_layui_i_b">
						<input type="radio" name="gender" value="1" title="男" checked="">
						<input type="radio" name="gender" value="2" title="女">
					</div>
				</div>
				<div class="layui-form-item cover_layui_f_i">
					<label class="layui-form-label cover_layui_f_l"> 身份证</label>
					<div class="layui-input-block cover_layui_i_b">
						<input type="text" name="id_card" placeholder="请输入身份证" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item cover_layui_f_i">
					<label class="layui-form-label cover_layui_f_l"> 微信号</label>
					<div class="layui-input-block cover_layui_i_b">
						<input type="text" name="contact_weixin" placeholder="请输入微信号" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item cover_layui_f_i">
					<label class="layui-form-label cover_layui_f_l"> QQ号</label>
					<div class="layui-input-block cover_layui_i_b">
						<input type="text" name="contact_qq" placeholder="请输入QQ号" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item cover_layui_f_i">
					<label class="layui-form-label cover_layui_f_l"> 邮箱</label>
					<div class="layui-input-block cover_layui_i_b">
						<input type="text" name="contact_email" placeholder="请输入邮箱" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item cover_layui_f_i">
					<label class="layui-form-label cover_layui_f_l"> 企业名称</label>
					<div class="layui-input-block cover_layui_i_b">
						<input type="text" name="company_name" placeholder="请输入企业名称" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item cover_layui_f_i">
					<label class="layui-form-label cover_layui_f_l"><span class="cover_new_label">*</span> 客户来源</label>
					<div class="layui-input-block cover_layui_i_b">
						<select name="source_type" id="source_type" required  lay-verify="required">
							<option value="">请选择客户来源</option>
							{volist name="$source_type" id="k" key="v"}
								<option value="{$v}">{$k}</option>
							{/volist}
						</select>
					</div>
				</div>
				<div class="layui-form-item cover_layui_f_i">
					<label class="layui-form-label cover_layui_f_l">推荐人电话</label>
					<div class="layui-input-block cover_layui_i_b">
						<input type="text" name="source" placeholder="请输入推荐人电话" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item cover_layui_f_i">
					<label class="layui-form-label cover_layui_f_l"> 地址</label>
					<input type="hidden" name="province" value="" />
					<input type="hidden" name="city" value="" />
					<input type="hidden" name="area" value="" />
					<div class="layui-input-inline">
						<select name="province_code" lay-filter="province">
							<option value="">请选择省</option>
							{volist name="$province" id="k"}
								<option value="{$k.id}">{$k.area_name}</option>
							{/volist}
						</select>
					</div>
					<div class="layui-input-inline">
						<select name="city_code" id="city" lay-filter="city">
							<option value="">请选择市</option>
						</select>
					</div>
					<div class="layui-input-inline">
						<select name="area_code" id="area" lay-filter="area">
							<option value="">请选择区/县</option>
						</select>
					</div>
				</div>
				<div class="layui-form-item cover_layui_f_i">
					<label class="layui-form-label cover_layui_f_l"> 详细地址</label>
					<div class="layui-input-block cover_layui_i_b">
						<input type="text" name="user_address" placeholder="请输入详细地址" autocomplete="off" class="layui-input">
					</div>
				</div>
			</div>
			<div class="layui-form-item ">
				<div class="layui-input-block cover_layui_i_b">
					<button class="layui-btn newBtnDefault newBtnPrimary" lay-submit lay-filter="formDemo">保存</button>
					<a href="javascript:(0)" class="layui-btn newBtnDefault" onclick="reset()">重置</a>
				</div>
			</div>
		</div>
	</form>

</div>


<script>
var layer = layui.layer,
		element = layui.element,
		laydate = layui.laydate,
		laypage = layui.laypage,
		form = layui.form,
		upload = layui.upload,
		layedit = layui.layedit;
form.render();
$('.cover_date').each(function(){
	laydate.render({
		elem: this,
	})
})
$('.cover_time').each(function(){
	laydate.render({
		elem: this,
		type: 'time'
	})
})

// 监听表单提交
var flag = false;
form.on('submit(formDemo)', function(data){
    if(flag){
        return false;
    }
    flag = true;
	// ajax请求
    $.post("{:url('add')}",data.field,function(e){
		if(e.code == 1000){
            top.layer.msg(e.msg, {icon: 1,time: 2000},function() {
                top.layer.close();
                window.location.href = "{:url('index')}";
            });
		}else{
            top.layer.msg(e.msg, {icon: 0,time: 2000});
        }
        flag = false;
    },'json');
    return false;
});

//重置
function reset() {
    top.layer.confirm('你确定要重置吗?', {
        btn: ['确定', '取消'] //按钮
    }, function() {
        $("form")[0].reset();
        top.layer.msg('重置成功', {
            icon: 1
        });
    });
}

// 省变化的时候
form.on('select(province)',function(data){
    var province_code = data.value;
    var province  = data.elem[data.elem.selectedIndex].text;
    $("input[name='province']").val(province);
    $("input[name='city']").val('');
    $("input[name='area']").val('');

    $('#city').html('');
    $('#area').html('');
    // ajax请求
	$.ajax({
		url: "{:url('/commonapi/Common/getArea')}",
        type: 'POST',
        contentType: 'application/json; charset=UTF-8',
        dataType: 'json',
    	data: JSON.stringify({pid: province_code}),
		success:function(res){
		    if(res.code == 1000) {
		        var str = '<option value="">请选择市</option>';
		        $.each(res.data,function(k,v) {
		            str += '<option value="'+ v.id +'">'+ v.area_name +'</option>';
				})
                $('#city').html(str);
                form.render();
			}
		},
	})
})

// 市变化的时候
form.on('select(city)',function(data){
    var city_code = data.value;
    var city  = data.elem[data.elem.selectedIndex].text;
    $("input[name='city']").val(city);
    $("input[name='area']").val('');

    $('#area').html('');
    // ajax请求
    $.ajax({
        url: "{:url('/commonapi/Common/getArea')}",
        type: 'POST',
        contentType: 'application/json; charset=UTF-8',
        dataType: 'json',
        data: JSON.stringify({pid: city_code}),
        success:function(res){
            if(res.code == 1000) {
                var str = '<option value="">请选择区/县</option>';
                $.each(res.data, function(k,v) {
                    str += '<option value="'+ v.id +'">'+ v.area_name +'</option>';
                })
                $('#area').html(str);
                form.render();
            }
        },
    })
})

// 区/县变化的时候
form.on('select(area)',function(data){
    var area = data.elem[data.elem.selectedIndex].text;
    $("input[name='area']").val(area);
})

</script>